#
#  SSF.App.Worm validation test Makefile
#

SHELL = /bin/sh


# ----- SETUP -----------------------------------------------------------------

TOPDIR = ../../../../..
include $(TOPDIR)/Makefile.common

JAVAC = javac -classpath $(SSFNET_TEST_CLASSPATH)
JAVA  = java  -classpath $(SSFNET_TEST_CLASSPATH)

# ----- MAKE TESTS ------------------------------------------------------------

tests: single_host two_as_single_host two_as_traffic single_host_stochastic
	@echo '-------- SSF.App.Worm testing complete --------'
	@echo ''


# ----- test: single host -----------------------------------------------------

single_host: 
	@echo '---------------- testing single_host: simple homogeneous model'
	@rm -f test-raw.out singleHost.out
	$(JAVA) SSF.Net.Net 72000 singleHost.dml > test-raw.out 2>&1
	@egrep "(Macroscopic)|(infected)" test-raw.out > singleHost.out
	@cat test-raw.out | perl singleHostDataExtr.pl > singleHost_epidemic.txt
	@echo '---------------- single_host: completed (see singleHost.out)'
	@echo
	@if [ -z "`diff singleHost.out singleHost.ref`" ]; \
	then \
	  echo ' **** TEST SUCCESSFUL ****   (singleHost.out & singleHost.ref identical)'; \
	else \
	  echo ' **** TEST FAILED ****   (singleHost.out & singleHost.ref differ)'; \
	fi
	@echo

# ----- test: 2 AS w/ single hosts --------------------------------------------

two_as_single_host: 
	@echo '------------ testing two_as_single_host: simple stratified model'
	@rm -f test-raw.out twoASsingleHosts.out
	$(JAVA) SSF.Net.Net 72000 twoASsingleHosts.dml > test-raw.out 2>&1
	@egrep "(Macroscopic)|(infected)" test-raw.out > twoASsingleHosts.out
	@echo '------------ two_as_single_host: completed (see twoASsingleHosts.out)'
	@echo
	@if [ -z "`diff twoASsingleHosts.out twoASsingleHosts.ref`" ]; \
	then \
	  echo ' **** TEST SUCCESSFUL ****   (twoASsingleHosts.out & twoASsingleHosts.ref identical)'; \
	else \
	  echo ' **** TEST FAILED ****   (twoASsingleHosts.out & twoASsingleHosts.ref differ)'; \
	fi
	@echo

# ----- test: traffic at 2 ASes -----------------------------------------------

two_as_traffic: TestWormEpidemicInitializer.class
	@echo '------------ testing two_as_traffic: simple egress scan traffic model'
	@rm -f test-raw.out twoAStraffic.out
	$(JAVA) SSF.Net.Net 72000 twoAStraffic.dml > test-raw.out 2>&1
	@egrep "(scans)" test-raw.out > twoAStraffic.out
	@awk '/Router 0:0/ {print $$2 " " $$8}' test-raw.out > twoAStraffic_r0.txt
	@awk '/Router 1:0/ {print $$2 " " $$8}' test-raw.out > twoAStraffic_r1.txt
	@./twoAStrafficDataExtr.pl test-raw.out
	@echo '------------ two_as_traffic: completed (see twoAStraffic.out)'
	@echo
	@if [ -z "`diff twoAStraffic.out twoAStraffic.ref`" ]; \
	then \
	  echo ' **** TEST SUCCESSFUL ****   (twoAStraffic.out & twoAStraffic.ref identical)'; \
	else \
	  echo ' **** TEST FAILED ****   (twoAStraffic.out & twoAStraffic.ref differ)'; \
	fi
	@echo

TestWormEpidemicInitializer.class:	TestWormEpidemicInitializer.java
	$(JAVAC) $(USERCFLAGS) TestWormEpidemicInitializer.java


# ----- test: single host stochastic ------------------------------------------

single_host_stochastic: 
	@echo '------------ testing single_host_stochastic: simple stochastic homogeneous model'
	@rm -f test-raw.out singleHostStoch.out
	$(JAVA) SSF.Net.Net 72000 singleHostStoch.dml > test-raw.out 2>&1
	@egrep "(Macroscopic)|(infected)" test-raw.out > singleHostStoch.out
	@cat test-raw.out | perl singleHostDataExtr.pl > singleHostStoch_epidemic.txt
	@echo '------------ single_host: completed (see singleHostStoch.out)'
	@echo
	@if [ -z "`diff singleHostStoch.out singleHostStoch.ref`" ]; \
	then \
	  echo ' **** TEST SUCCESSFUL ****   (singleHostStoch.out & singleHostStoch.ref identical)'; \
	else \
	  echo ' **** TEST FAILED ****   (singleHostStoch.out & singleHostStoch.ref differ)'; \
	fi
	@echo

# ----- graphs ----------------------------------------------------------------

graphs: singleHost_epidemic.txt singleHostStoch_epidemic.txt twoAStraffic_r0.txt twoAStraffic_r1.txt twoAStraffic_epidemic.txt
	@echo 'deterministic/stochastic comparison -> singleHost_comp.png'
	@gnuplot singleHost_comp_png.gnuplot
	@echo 'scan traffic in two ASes -> twoAStraffic.png'
	@gnuplot twoAStraffic_png.gnuplot

# ----- MAKE CLEAN ------------------------------------------------------------

clean:
	@rm *.out *.txt *.class *.png

# ----- MAKE SPOTLESS ---------------------------------------------------------

spotless: clean
	@find . \( -name "*.class" -o -name ".*~" -o -name "*~" \) -exec rm -f {} \; > /dev/null 2>&1
	@echo 'Done.'
